$import( "SmitearWebGL.Objects.Parser.Collada.DaeEntity" );
$import( "SmitearWebGL.Objects.Parser.Collada.DaeBindVertexInput" );

SmitearWebGL.Objects.Parser.Collada.DaeInstanceMaterial = SmitearWebGL.Objects.Parser.Collada.DaeEntity.extend(
{
	/******** constructor ********/

	init : function( document, node )
	{
		/******** public property ********/

		this.symbol = "";
		this.target = "";

		/******** private property ********/

		this._bindVertexInputs = null;

		this._super( document, node );
		this._registClass( "SmitearWebGL.Objects.Parser.Collada.DaeInstanceMaterial" );
	}
	,
	getBindVertexInputs : function()
	{
		return this._bindVertexInputs;
	}
	,
	findBindVertexInput : function( semantic, input_semantic )
	{
		input_semantic = input_semantic == undefined ? "TEXCOORD" : input_semantic;
		
		for ( var i = 0; i < this._bindVertexInputs.length; ++ i )
		{
			var obj = this._bindVertexInputs[i];
			if( obj.semantic == semantic && obj.input_semantic == input_semantic )
			return obj;
		}
		return null;
	}
	,
	read : function( node )
	{
		this._super( node );

		this.symbol = this.getAttribute(node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_SYMBOL_ATTRIBUTE);
		this.target = this.getAttribute(node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_TARGET_ATTRIBUTE);

		this._bindVertexInputs = [];

		var list = node.childNodes;

		for( var i = 0; i < list.length; i++ )
		{
			var child = list[i];

			switch( child.localName )
			{
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_BIND_ELEMENT:
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_BIND_VERTEX_INPUT:
					this._bindVertexInputs.push(new SmitearWebGL.Objects.Parser.Collada.DaeBindVertexInput(this.document, child));
					break;
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_EXTRA_ELEMENT:
					break;
				default:
					break;
			}
		}
	}
}
);